package schedule;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.nio.charset.StandardCharsets;
import java.time.LocalTime;

/**
 * 预定日程生产者
 */
public class ScheduleProducer {
    public static void main(String[] args) throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
        DefaultMQProducer producer =new DefaultMQProducer("ScheduleProducer");
        producer.setNamesrvAddr("");
        producer.start();
        for (int i =0;i<10;i++){
            Message message = new Message("Schedule","Tags",(i+"_ScheduleProducer").getBytes(StandardCharsets.UTF_8));
            //延时设置1到18,分别对应messageDelayLevel=1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
            message.setDelayTimeLevel(2);
            producer.send(message);
            System.out.println("消息发送成功"+LocalTime.now());

        }
        producer.shutdown();
    }
}
